package main.java.work;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@SpringBootApplication
@RestController
@RequestMapping("/test")
@CrossOrigin(origins = "*") // 允许所有来源
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    /* ------ GET ------ */
    @GetMapping
    public Map<String, Object> testGet(@RequestParam(required = false) String user_n) {
        return Map.of("method", "GET", "user_n", user_n == null ? "" : user_n);
    }

    /* ------ POST ------ */
    @PostMapping
    public Map<String, Object> testPost(@RequestParam(required = false) String post_user,
                                    @RequestParam(required = false) String post_password) { // 新增
     return Map.of("method", "POST",
                "post_user", post_user == null ? "" : post_user,
                "password", post_password == null ? "" : post_password); // 新增
    }
}